﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <script src="/js/header.js"></script>
</head>
<body style="background-color: white;">
    <div class="data-wrap" style="margin:5px;">
        <div class="data-tool clearfix">
            <div class="pull-left form-inline ">
            </div>
            <div class="pull-right">
                <form class="form-inline" id="formSearch" onsubmit="return false;">
                    <div class="input-group input-group-sm">
                        <label class="input-group-addon">匹配时间(分)：</label>
                        <input class="form-control" name="minutes" type="text" maxlength="4" value="15" placeholder="介于 10 和 1440 之间">
                    </div>
                    <button type="button" class="btn btn-default btn-sm active" id="btnSearch"><span class="glyphicon glyphicon-search"></span> 搜索</button>
                </form>
            </div>
        </div>
        <div class="paging"></div>
        <div class="form-group aui_footer" style="margin-top:25px;padding: 10px 15px;border-top: 1px solid #e5e6e7;">
            <div class="t_c">
                <button class="btn btn-warning m50_l hide" name="emptyrecordturnsuccess">转成功</button>
                <button class="btn btn-primary m50_l hide" name="turnsuccess">转成功</button>
                <button class="btn btn-default m10_l hide" name="turnfailure">转失败</button>
                <button class="btn btn-danger f_r hide" name="renewpayment">重新付款</button>
            </div>
        </div>
    </div>
    <script type="text/x-dot-template" id="templatePager">
        <div class="data-body data-scroll">
            <div class="data-div-view">
                <table class="table table-hover table-striped table-bordered">
                    <thead>
                        <tr>
                            <th class="wd50"></th>
                            <th class="t_l wd100">公司名称</th>
                            <th class="wd150">付款时间</th>
                            <th class="t_l wd100">付款银行</th>
                            <th class="t_r wd75">付款金额</th>
                            <th class="t_l wd150">客户银行</th>
                            <th class="t_l wd100">客户姓名</th>
                            <th class="t_l wd150">客户卡号</th>
                        </tr>
                    </thead>
                    <tbody>
                        {{? it && it.length>0}}
                        {{ for(var prop in it) { }}
                        <tr>
                            <td class="wd50"><input type="radio" name="orderNo" value="{{=it[prop]['orderNo']}}" /></td>
                            <td class="t_l wd100">{{=it[prop]['companyName']}}</td>
                            <td class="wd150" title="{{=it[prop]['operatingDate']}}">{{=it[prop]['operatingDate']}}</td>
                            <td class="t_l wd100" title="{{=it[prop]['cardBankName']}}">{{=it[prop]['cardBankName']}}</td>
                            <td class="t_r bold wd75">{{=it[prop]['amount']}}</td>
                            <td class="t_l wd150" title="{{=it[prop]['clientBankName']}}">{{=it[prop]['clientBankName']}}</td>
                            <td class="t_l wd100" title="{{=it[prop]['clientAccountName']}}">{{=it[prop]['clientAccountName']}}</td>
                            <td class="t_l wd150" title="{{=it[prop]['clientCardNumber']}}">{{=it[prop]['clientCardNumber']}}</td>
                        </tr>
                        {{ } }}
                        {{??}}
                        <tr class="noRecord">
                            <td colspan="9">暂无记录！</td>
                        </tr>
                        {{?}}
                    </tbody>
                </table>
            </div>
        </div>
    </script>
    <script type="text/javascript">
        var parent = artDialog.open.origin;

        var orderNo;

        $(function () {
            orderNo = FlashPay.Util.GetQueryString("orderNo");

            init();

            $("#btnSearch").click(function () {
                init();
            });

            //转成功
            $("button[name='turnsuccess']").click(function () {

                var isSelected = $("input[name='orderNo']:checked").val();

                if (FlashPay.Util.isNullOrEmptySpance(isSelected)) {

                    FlashPay.UI.Confirm({
                        content: "您确定不选择实现付款记录<span class='red'>转成功</span>该订单吗？",
                        ok: function () {

                            var cover = FlashPay.UI.Mask({
                                obj: $("body"),
                                opacity: 0.5
                            });

                            var minutes = $("input[name='minutes']").val();

                            FlashPay.Util.Ajax({
                                type: "POST",
                                url: "/Payment/EmptyRecordTurnSuccess",
                                data: { orderNo: orderNo, minutes: minutes },
                                dataType: "json",
                                success: function (response) {
                                    if (response != null && response.success) {
                                        FlashPay.UI.DialogOpener().Tip_success("操作成功！");
                                        FlashPay.UI.DialogOpener().doSearch();
                                        FlashPay.UI.CloseDialog();
                                    } else {
                                        cover.Remove();

                                        FlashPay.UI.Tip_short_warning("操作失败:" + response.errorMessage);
                                    }
                                },
                                error: function (e) {
                                    cover.Remove();

                                    FlashPay.UI.Tip_short_warning("操作失败！请查看网络，请重试！");
                                }
                            });
                        }
                    });

                } else {
                    FlashPay.UI.Confirm({
                        content: "确定要<span class='red'>转成功</span>该订单吗？",
                        ok: function () {

                            var cover = FlashPay.UI.Mask({
                                obj: $("body"),
                                opacity: 0.5
                            });

                            FlashPay.Util.Ajax({
                                type: "POST",
                                url: "/Payment/TurnSuccess",
                                data: { orderNo: orderNo, RecordRealOrderNo: $("input[name='orderNo']:checked").val() },
                                dataType: "json",
                                success: function (response) {
                                    if (response != null && response.success) {
                                        FlashPay.UI.DialogOpener().Tip_success("操作成功！");
                                        FlashPay.UI.DialogOpener().doSearch();
                                        FlashPay.UI.CloseDialog();
                                    } else {
                                        cover.Remove();

                                        FlashPay.UI.Tip_short_warning("操作失败:" + response.errorMessage);
                                    }
                                },
                                error: function (e) {
                                    cover.Remove();

                                    FlashPay.UI.Tip_short_warning("操作失败！请查看网络，请重试！");
                                }
                            });

                        }
                    });
                }
            });

            //转成功
            $("button[name='emptyrecordturnsuccess']").click(function () {

                FlashPay.UI.Confirm({
                    content: "确定要<span class='red'>转成功</span>该订单吗？",
                    ok: function () {

                        var cover = FlashPay.UI.Mask({
                            obj: $("body"),
                            opacity: 0.5
                        });

                        var minutes = $("input[name='minutes']").val();

                        FlashPay.Util.Ajax({
                            type: "POST",
                            url: "/Payment/EmptyRecordTurnSuccess",
                            data: { orderNo: orderNo, minutes: minutes },
                            dataType: "json",
                            success: function (response) {
                                if (response != null && response.success) {
                                    FlashPay.UI.DialogOpener().Tip_success("操作成功！");
                                    FlashPay.UI.DialogOpener().doSearch();
                                    FlashPay.UI.CloseDialog();
                                } else {
                                    cover.Remove();

                                    FlashPay.UI.Tip_short_warning("操作失败:" + response.errorMessage);
                                }
                            },
                            error: function (e) {
                                cover.Remove();

                                FlashPay.UI.Tip_short_warning("操作失败！请查看网络，请重试！");
                            }
                        });

                    }
                });

                
            });

            //转失败
            $("button[name='turnfailure']").click(function () {

                FlashPay.UI.Confirm({
                    content: "确定要<span class='red'>转失败</span>该订单吗？",
                    ok: function () {
                        var cover = FlashPay.UI.Mask({
                            obj: $("body"),
                            opacity: 0.5
                        });

                        FlashPay.Util.Ajax({
                            type: "POST",
                            url: "/Payment/TurnFailure",
                            data: { orderNo: orderNo },
                            dataType: "json",
                            success: function (response) {
                                if (response != null && response.success) {
                                    FlashPay.UI.DialogOpener().Tip_success("操作成功！");
                                    FlashPay.UI.DialogOpener().doSearch();
                                    FlashPay.UI.CloseDialog();
                                } else {
                                    cover.Remove();
                                    FlashPay.UI.DialogOpener().doSearch();
                                    FlashPay.UI.Tip_short_warning("操作失败:" + response.errorMessage);
                                }
                            },
                            error: function (e) {
                                cover.Remove();

                                FlashPay.UI.Tip_short_warning("操作失败！请查看网络，请重试！");
                            }
                        });
                    }
                });
                
            });
            //重新付款
            $("button[name='renewpayment']").click(function () {

                FlashPay.UI.Confirm({
                    content: "确定要<span class='red'>重新付款</span>该订单吗？",
                    ok: function () {
                        var cover = FlashPay.UI.Mask({
                            obj: $("body"),
                            opacity: 0.5
                        });

                        FlashPay.Util.Ajax({
                            type: "POST",
                            url: "/Payment/RenewPayment",
                            data: { orderNo: orderNo },
                            dataType: "json",
                            success: function (response) {
                                if (response != null && response.success) {
                                    FlashPay.UI.DialogOpener().Tip_success("操作成功！");
                                    FlashPay.UI.DialogOpener().doSearch();
                                    FlashPay.UI.CloseDialog();
                                } else {
                                    cover.Remove();
                                    FlashPay.UI.DialogOpener().doSearch();
                                    FlashPay.UI.Tip_short_warning("操作失败:" + response.errorMessage);
                                }
                            },
                            error: function (e) {
                                cover.Remove();

                                FlashPay.UI.Tip_short_warning("操作失败！请查看网络，请重试！");
                            }
                        });
                    }
                });
                
            });
        });

        $(document).keyup(function (event) {
            var keycode = event.which;
            if (keycode == 13) {
                init();
            }
        }); 

        function init() {
            var minutes = $("input[name='minutes']").val();

            if (FlashPay.Util.isNullOrEmptySpance(minutes)) {
                FlashPay.UI.Tip_short_warning("匹配时间不能为空！");
                return;
            }

            var regx = /^[1-9]+[0-9]*]*$/;
            if (!regx.test(minutes)) {
                FlashPay.UI.Tip_short_warning("匹配时间只能为正整数！");
                return;
            }

            var cover = FlashPay.UI.Mask({
                obj: $("body"),
                opacity: 0.5
            });

            FlashPay.Util.Ajax({
                type: "POST",
                url: "/Payment/PaymentRecordReals?orderNo=" + orderNo + "&minutes=" + minutes,
                data: null,
                dataType: "json",
                success: function (response) {
                    if (response != null && response.success) {
                        cover.Remove();
                        debugger
                        if (response.paymentDateTimeDifference < response.minutes) {
                            $("button[name='renewpayment']").remove();
                        }

                        var text = doT.template($("#templatePager").text());
                        $(".paging").html("");
                        $(".paging").append(text(response.data));

                        if (response.statusCode != "PaymentRecord0010") {
                            $("button[name='renewpayment']").remove();
                        }
                        if (response.data.length > 0) {
                            $("button[name='turnsuccess']").removeClass("hide");
                            $("button[name='turnfailure']").removeClass("hide");
                            $("button[name='emptyrecordturnsuccess']").remove();
                            $("button[name='renewpayment']").removeClass("hide");
                        } else {
                            $("button[name='turnsuccess']").remove();
                            $("button[name='emptyrecordturnsuccess']").removeClass("hide");
                            $("button[name='turnfailure']").removeClass("hide");
                            $("button[name='renewpayment']").removeClass("hide");
                        }
                    } else {
                        cover.Remove();
                        $("button[name='turnsuccess']").remove();
                        $("button[name='turnfailure']").remove();
                        $("button[name='emptyrecordturnsuccess']").remove();
                        $("button[name='renewpayment']").remove();
                        FlashPay.UI.Tip_short_warning(response.errorMessage);
                    }
                },
                error: function (e) {
                    cover.Remove();

                    FlashPay.UI.Tip_short_warning("操作失败！请查看网络，请重试！");
                }
            });
        }
    </script>
</body>
</html>